package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursingLevel")
@Slf4j
@Api(tags = "护理等级")
public class NursingLevelController extends BaseController{
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 分页查询护理等级
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listByPage")
    @ApiOperation("分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> selectPage(@ApiParam(value = "护理项目名称")String name,
                                                                 @ApiParam(value = "护理项目状态") Integer status,
                                                                 @ApiParam(value = "分页页码")@RequestParam(value = "pageNum", defaultValue = "1")Integer pageNum,
                                                                 @ApiParam(value = "每页显示记录数")@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.selectPage(name,status,pageNum,pageSize);
        return success(pageResponse);
    }

    /**
     * 新增护理等级
     * @param nursingLevelDto
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation("新增等级")
    public ResponseResult add(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.add(nursingLevelDto);
        return success();
    }

    /**
     * 根据Id查询等级
     * @param id
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("根据Id查询等级")
    public ResponseResult<NursingLevelVo> getById(@ApiParam(value = "Id")@PathVariable Integer id){
        NursingLevelVo nursingLevelVo =  nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    /**
     * 更新护理等级
     * @param nursingLevelDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("更新护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    /**
     * 根据Id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据Id删除等级")
    public ResponseResult delete(@ApiParam(value = "Id")@PathVariable Integer id){
        nursingLevelService.delById(id);
        return success();
    }
    /**
     * 启用或者禁用
     * @param status
     * @param id
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用和禁用护理项目")
    public ResponseResult startOrStop(@PathVariable Integer status,@PathVariable Integer id){
        nursingLevelService.startOrstop(status,id);
        return success();
    }
}
